2026-09-20 · linux, class-notes
When you type a name at the prompt, it can be any one of four things:
Class notes · William Shotts, The Linux Command Line · Chapter 5
Quick reference: the short version of this chapter is the Chapter 5 cheat sheet.
By the end of these notes you should be able to:
When you type a name at the prompt, it can be any one of four things:
Kind
What it is
Example
Executable program
A file on disk, like those in /usr/bin. Can be compiled (C, C++, Rust) or a script (Bash, Python, Perl)
ls, cp, python3
Shell builtin
A command built into Bash itself; no separate file
cd, echo, type, help
Shell function
A mini shell script stored in the shell's environment
Defined in startup files — covered later in the book
Alias
Your own name for another command or string of commands
ll for ls -l on many systems
Why builtins exist: some jobs must happen inside the shell process. cd changes the shell's own current directory — a separate program couldn't do that, because it would only change its own.
type is a shell builtin that tells you how the shell will interpret a name:
$ type type type is a shell builtin $ type cd cd is a shell builtin $ type cp cp is /usr/bin/cp $ type ls ls is aliased to `ls --color=auto'The last line is typical of Ubuntu and many other distributions: ls is an alias that adds colour. When you type ls, you're really running ls --color=auto.
which shows the location of an executable program found on your search path:
$ which ls /usr/bin/ls $ which cd $- which cd prints nothing on many systems (or a "no cd in ..." message on others), because cd isn't a program on disk — it's a builtin.
A colleague's rm asks for confirmation on every file, but yours doesn't.
This explains many "it works differently on that machine" puzzles. Check type before assuming the program itself differs.
Bash has built-in documentation for its builtins:
$ help cd cd: cd [-L|[-P [-e]] [-@]] [dir] Change the shell working directory. ...
Reading the syntax line:
Notation
Means
[ ]
Optional
|
Choose one of these (mutually exclusive)
...
Can repeat
So cd [-L|[-P [-e]]] [dir]:
Most executable programs (especially the GNU tools) print a usage summary with --help:
$ mkdir --help Usage: mkdir [OPTION]... DIRECTORY... Create the DIRECTORY(ies), if they do not already exist. -m, --mode=MODE set file mode (as in chmod a=rwx), not a=rwx - umask -p, --parents no error if existing, make parent directories as needed ...Not every program supports --help, but trying it is harmless — at worst you get an error message, which often includes the usage anyway.
Most command-line programs ship with a formal man page (manual page). man displays it, using less as the pager, so all the less keys work: Space to page, / to search, q to quit.
man ls
A typical man page layout:
Section heading
Contains
NAME
The command and a one-line description
SYNOPSIS
The syntax, in the notation above
DESCRIPTION
What it does, and every option
EXAMPLES
Sometimes — not every page has them
SEE ALSO
Related commands and pages
Man pages are reference documents, not tutorials. They tell you precisely what each option does, but rarely why you'd use it. Reading them is a skill that improves with practice.
The manual is split into numbered sections, and the same name can appear in more than one:
Section
Contents
1
User commands
2
Programming interfaces for kernel system calls
3
Programming interfaces to the C library
4
Special files, such as device nodes and drivers
5
File formats
6
Games and amusements (such as screen savers)
7
Miscellaneous
8
System administration commands
passwd is both a command (to change a password) and a file (/etc/passwd, which lists accounts).
man 5 passwd1. In documentation you'll see this written as passwd(5) — the name with its section in brackets.
When you don't know a command's name, search the manual by keyword:
$ apropos partition addpart (8) - tell the kernel about the existence of a partition cfdisk (8) - display or manipulate a disk partition table fdisk (8) - manipulate disk partition table ...- apropos searches man page names and short descriptions. man -k does the same thing.
$ whatis ls ls (1) - list directory contents
Note: apropos and whatis rely on a database of man page descriptions. If they return nothing on a fresh system, the database may need building (sudo mandb). Some minimal installs and containers omit man pages entirely.
Key in info
Does
Space / Page Down
Next page
Enter on a link
Follow it
u
Up to the parent node
n / p
Next / previous node
q
Quit
Question
First place to look
How do I use cd's options?
help cd (it's a builtin)
What options does cp have?
cp --help, then man cp for detail
Is there a command for managing partitions?
apropos partition
What's the format of /etc/fstab?
man 5 fstab
What does this package's config file support?
/usr/share/doc/
Separate commands with a semicolon and they run one after another:
cd /usr; ls; cd -This goes to /usr, lists it, then returns to where you started.
$ type foo bash: type: foo: not found1. Create the alias. The syntax is alias name='string', with no spaces around the =:
alias foo='cd /usr; ls; cd -'1. Test it: type foo — it lists /usr and brings you back. 2. Confirm what it is:
$ type foo foo is aliased to `cd /usr; ls; cd -'1. Remove it when you no longer want it:
unalias foo
Command
Does
alias
List every alias defined in this shell
alias name='string'
Create or replace an alias
unalias name
Remove an alias
type name
Show whether a name is an alias, and what it expands to
Aliases disappear when the shell session ends. To keep them, add them to a startup file such as ~/.bashrc — covered later in the book.
Term
Definition
Executable program
A command stored as a file on disk
Compiled program
A program translated to machine code, e.g. from C
Script
A program run by an interpreter, e.g. Bash or Python
Shell builtin
A command built into the shell itself
Shell function
A small shell script stored in the shell's environment
Alias
A user-defined name standing in for another command or commands
type
Shows how the shell interprets a command name
which
Shows the location of an executable program
help
Displays help for Bash builtins
--help
A common option that prints a program's usage summary
Man page
A formal reference document for a command, file or interface
Man page section
A numbered part of the manual, e.g. 1 (commands) or 5 (file formats)
SYNOPSIS
The man page section showing a command's syntax
apropos / man -k
Search man page names and descriptions by keyword
whatis
Show a command's one-line man page description
info
The GNU hyperlinked documentation reader
/usr/share/doc
Directory of package documentation
zless
Read gzip-compressed text files
unalias
Remove an alias
Command separator (;)
Runs commands one after another on one line